﻿namespace MobileTrack.Web
{
    using System;
    using System.Data.Services;
    using System.Data.Services.Common;
    using System.Diagnostics.CodeAnalysis;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using MobileTrack.Core.Data;

    [ExcludeFromCodeCoverage]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class Reporting : DataService<MobileTrackContext>
    {
        public static void InitializeService(DataServiceConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            config.SetEntitySetAccessRule("Celulares", EntitySetRights.AllRead);
            config.SetEntitySetAccessRule("Abonos", EntitySetRights.AllRead);
            config.SetEntitySetAccessRule("Seguimientos", EntitySetRights.AllRead);
            config.SetEntitySetAccessRule("Ventas", EntitySetRights.AllRead);
            config.SetEntitySetAccessRule("Sucursales", EntitySetRights.AllRead);
            config.SetEntitySetAccessRule("Proveedores", EntitySetRights.AllRead);
            config.SetEntitySetAccessRule("Marcas", EntitySetRights.AllRead);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
            config.UseVerboseErrors = true;
        }

        protected override MobileTrackContext CreateDataSource()
        {
            return new MobileTrackContext(MobileTrackApplication.ConnectionStringName);
        }
    }
}
